/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vista;

import Modelo.*;
import Modelo.Clases.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author cltsmalc
 */
public class AncianoJPanel extends javax.swing.JPanel {

    /**
     * Creates new form AncianoJPanel
     */
     ArrayList lista = new ArrayList();
    int filaSeleccionada = 0;
    public AncianoJPanel() {
        initComponents();
    }
    
    public AncianoJPanel(int width , int height) {
        initComponents();
        this.setSize(width, height);
        this.setVisible(true);
        
        List<Anciano> lista = Modelo.consultarAncianos();
        
         for(int i =0 ; i < lista.size();i++){

            
            this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getEdad(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
            
           
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jEImagePanel1 = new recursos.JEImagePanel();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jLabel5 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField4 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jDateChooser2 = new com.toedter.calendar.JDateChooser();
        jButton5 = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(923, 575));

        jEImagePanel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/magic-wind-blue.jpg"))); // NOI18N

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField1KeyTyped(evt);
            }
        });

        jLabel1.setText("Nombre:");

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });
        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField2KeyTyped(evt);
            }
        });

        jLabel2.setText("Apellido:");

        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });
        jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField3KeyTyped(evt);
            }
        });

        jLabel4.setText("Cedula:");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "activo", "inactivo", "eliminado"}));
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

        jLabel7.setText("Estado:");

        jLabel5.setText(" Nacimiento:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "masculino", "femenino" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel6.setText("Genero:");

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Add.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel8.setBackground(new java.awt.Color(204, 255, 153));
        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel8.setForeground(new java.awt.Color(102, 102, 255));
        jLabel8.setText("Ingreso de Paciente");

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Pencil_2.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Trash_Delete.png"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Nombre", "Apellido", "Edad", "Cedula", "Estado"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField4KeyReleased(evt);
            }
        });

        jLabel3.setText("Fecha de Ingreso:");

        jButton5.setBackground(new java.awt.Color(255, 255, 255));
        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/buscar.png"))); // NOI18N

        javax.swing.GroupLayout jEImagePanel1Layout = new javax.swing.GroupLayout(jEImagePanel1);
        jEImagePanel1.setLayout(jEImagePanel1Layout);
        jEImagePanel1Layout.setHorizontalGroup(
            jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jEImagePanel1Layout.createSequentialGroup()
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(69, 69, 69)
                        .addComponent(jLabel8))
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel3))
                                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                        .addGap(14, 14, 14)
                                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(jDateChooser1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jTextField3)
                                            .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(jDateChooser2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                            .addComponent(jButton1))))
                .addGap(39, 39, 39)
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 390, Short.MAX_VALUE)
                        .addComponent(jButton4))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jEImagePanel1Layout.createSequentialGroup()
                .addContainerGap(468, Short.MAX_VALUE)
                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36))
        );
        jEImagePanel1Layout.setVerticalGroup(
            jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jEImagePanel1Layout.createSequentialGroup()
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addGap(51, 51, 51)
                                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addGap(43, 43, 43)
                                .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(50, 50, 50)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(95, 95, 95)
                        .addComponent(jLabel8)
                        .addGap(30, 30, 30)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(27, 27, 27)
                                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6))))
                        .addGap(26, 26, 26)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))))
                .addGap(18, 18, 18)
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButton1)
                        .addComponent(jButton4))
                    .addComponent(jButton3))
                .addGap(26, 26, 26))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jEImagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jEImagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed

    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped

    }//GEN-LAST:event_jTextField1KeyTyped

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jTextField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyTyped

    }//GEN-LAST:event_jTextField2KeyTyped

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jTextField3ActionPerformed

    private void jTextField3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyTyped

    }//GEN-LAST:event_jTextField3KeyTyped

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      try{
        Anciano anciano = new Anciano();
        try{
           
          anciano.setNombre(jTextField1.getText());
          anciano.setApellido(jTextField2.getText());
          anciano.setCedula(jTextField3.getText());
          anciano.setGenero(jComboBox1.getSelectedItem().toString());
          anciano.setEstado(jComboBox2.getSelectedItem().toString());
          anciano.setFechaNacimiento(jDateChooser1.getDate());
          anciano.setFechaIngreso(jDateChooser2.getDate());
          Date actual = new Date();
          anciano.setEdad( actual.getYear() - jDateChooser1.getDate().getYear() );
            System.out.println(actual.getYear() - jDateChooser1.getDate().getYear());
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Datos incorrectos");
        }
       

        Modelo.guardar(anciano);
         initComponents();
         
         List<Anciano> lista = Modelo.consultarAncianos();
         this.setVisible(false);
         this.removeAll();
         initComponents();
         
           for(int i =0 ; i < lista.size();i++){

            
            this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getEdad(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
            
           
        }
         
             this.setVisible(true);
             
      }catch(Exception e){
      
      }
    }//GEN-LAST:event_jButton1ActionPerformed
int bandera = 0 ;
int id = -1 ;
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

        if(bandera == 0){
        Anciano anciano = Modelo.consultarAnciano(jTable1.getValueAt(jTable1.getSelectedRow(), 3)+"");
        
        if(anciano != null){
            id = anciano.getIdAnciano() ;
            jTextField1.setText(anciano.getNombre());
            jTextField2.setText(anciano.getApellido());
            jTextField3.setText(anciano.getCedula());
            
             if(anciano.getGenero().equalsIgnoreCase("masculino")){
            this.jComboBox1.setSelectedIndex(0);
            }
            if(anciano.getGenero().equalsIgnoreCase("femenino")){
            this.jComboBox1.setSelectedIndex(1);
            }
            
            this.jDateChooser1.setDate(anciano.getFechaNacimiento());
            this.jDateChooser2.setDate(anciano.getFechaIngreso());
            if(anciano.getEstado().equalsIgnoreCase("eliminado")){
            this.jComboBox2.setSelectedIndex(2);
                    }
            if(anciano.getEstado().equalsIgnoreCase("inactivo")){
            this.jComboBox2.setSelectedIndex(1);
                    }
            if(anciano.getEstado().equalsIgnoreCase("activo")){
            this.jComboBox2.setSelectedIndex(0);
                    }
            jLabel8.setText("Modificar");
            bandera = 1 ;
            jButton1.setEnabled(false);
            jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/guardar.png")));
            
            
        }else{
            JOptionPane.showMessageDialog(null, "Error al cargar los datos");
    }
            }else{

            
            Anciano anciano = Modelo.consultarAnciano(id);
            
            anciano.setNombre(jTextField1.getText());
            anciano.setApellido(jTextField2.getText());
            anciano.setCedula(jTextField3.getText());
            anciano.setGenero(jComboBox1.getSelectedItem()+"");
            anciano.setEstado(jComboBox2.getSelectedItem()+"");
            anciano.setFechaNacimiento(jDateChooser1.getDate());
            anciano.setFechaIngreso(jDateChooser2.getDate());
            Date d = new Date();
            anciano.setEdad(d.getYear() - jDateChooser1.getDate().getYear());
            
            
            Modelo.actualizar(anciano);
             initComponents();
         
         List<Anciano> lista = Modelo.consultarAncianos();
         this.setVisible(false);
         this.removeAll();
         initComponents();
         
           for(int i =0 ; i < lista.size();i++){

            
            this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getEdad(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
            
           
        }
         
             this.setVisible(true);
             
               bandera = 0 ;
           jButton1.setEnabled(true);
         jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Pencil_2.png")));
         JOptionPane.showMessageDialog(null,"Actualizado correctamente");
         this.jLabel8.setText("Ingreso de Administrador");
            
        }
        
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed

     
       
       Anciano a = Modelo.consultarAnciano(jTable1.getValueAt(jTable1.getSelectedRow(), 3)+"");
        
       Modelo.eliminar(a);
        initComponents();
         
         List<Anciano> lista = Modelo.consultarAncianos();
         this.setVisible(false);
         this.removeAll();
         initComponents();
         
           for(int i =0 ; i < lista.size();i++){

            
            this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getEdad(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 4);
            
           
        }
         
             this.setVisible(true);
    }//GEN-LAST:event_jButton4ActionPerformed

private void jTextField4KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField4KeyReleased
// TODO add your handling code here:
    
    String c = this.jTextField4.getText();
    
    List<Anciano> lista = Modelo.consultarAncianosCoincidencias(c);
    
    for(int i =0 ; i <jTable1.getRowCount();i++){

            this.jTable1.setValueAt("", i, 0);
            this.jTable1.setValueAt("", i, 1);
            this.jTable1.setValueAt("", i, 2);
            this.jTable1.setValueAt("", i, 3);
            
           
        }
     for(int i =0 ; i < lista.size();i++){
         
             this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getEdad(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 3);
            
        }
}//GEN-LAST:event_jTextField4KeyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private com.toedter.calendar.JDateChooser jDateChooser2;
    private recursos.JEImagePanel jEImagePanel1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    // End of variables declaration//GEN-END:variables
}
